import React from 'react';
import * as CONS from './flag';
let AppMap: any = {};

interface IProps {
  sceneFlag: string;
  route: any;
}

class AppGateWay extends React.Component<IProps> {
  constructor(props: IProps) {
    super(props);
  }
  getTagByFlag(flag: string) {
    switch (flag) {
      case CONS.APP_HOME:
        return require('../components/MainPage').default;
      case CONS.APP_MAP:
        return require('../components/MapPage').default;
      case CONS.APP_STUDY:
      case CONS.APP_WORK:
      case CONS.APP_CENTER:
      case CONS.GATE_WAY_PAY_ENTITY:
        return require('../components/PayEntity').default;
      case CONS.GATE_WAY_OBJECT_LIST:
        return require('../components/ObjectListPage').default;
      default:
        return require('../components/ObjectListPage').default;
    }
  }

  render() {
    console.log('[props]', this.props);
    const flag =
      this.props.sceneFlag || (this.props.route && this.props.route.name);
    let App = AppMap[flag];
    if (!App) {
      if (!AppMap[flag]) {
        AppMap[flag] = this.getTagByFlag(flag);
      }
      App = AppMap[flag];
    }
    if (!App) {
      return null;
    }
    return <App {...this.props} />;
  }
}
export default AppGateWay;
